package com.zzs.server.dao.mysql;

import com.zzs.common.core.entity.mysql.ProblemCodeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author zzs
 * @date 2025/03/18
 */
@Mapper
public interface ProblemCodeMapper {
    @Insert("insert into problem_code (id, problem_id, language, main_function, user_function, create_time, update_time)" +
            " VALUES (#{id}, #{problemId}, #{language}, #{mainFunction}, #{userFunction}, #{createTime}, #{updateTime})")
    int save(ProblemCodeDO problemCodeDO);

    @Select("select exists(select 1 from problem_code where problem_id = #{problemId} and language = #{language})")
    boolean exists(@Param("problemId") long problemId, @Param("language") int language);

    @Update("update problem_code set main_function = #{mainFunction}, user_function = #{userFunction}, update_time = #{updateTime} where problem_id = #{problemId} and language = #{language}")
    int update(ProblemCodeDO problemCodeDO);

    @Select("select problem_id, language, main_function, user_function from problem_code where problem_id = #{problemId} and language = #{language}")
    ProblemCodeDO get(@Param("problemId") long problemId, @Param("language") int language);

    @Select("select problem_id, language, main_function, user_function from problem_code where problem_id = #{problemId}")
    List<ProblemCodeDO> list(@Param("problemId") long problemId);

    @Select("select language from problem_code where problem_id = #{problemId}")
    List<Integer> listLanguage(@Param("problemId") long problemId);

    @Delete("delete from problem_code where problem_id = #{problemId} and language = #{language}")
    int remove(@Param("problemId") long problemCodeId, @Param("language") int language);

    @Delete("delete from problem_code where problem_id = #{problemId}")
    void removeByProblemId(@Param("problemId") long problemId);

    @Select("select exists(select 1 from problem_code where problem_id = #{problemId})")
    boolean existsByProblemId(@Param("problemId") long problemId);
}
